

use "$project\manager\manager_fe_tfp", clear
ren pe pe_tfp
collapse pe_, by (pnr)
save "$project\manager\managerfe_tfp", replace

use "$project\manager\manager_fe_vapp", clear
ren pe pe_vapp
collapse pe_, by (pnr)
save "$project\manager\managerfe_vapp", replace

use "$project\manager\manager_fe_tfp2", clear
ren pe pe_tfp2
collapse pe_, by (pnr)
save "$project\manager\managerfe_tfp2", replace

use "$project\manager\manager_fe_leverage", clear
ren pe pe_leverage
collapse pe_, by (pnr)
save "$project\manager\managerfe_leverage", replace

use "$project\manager\manager_fe_profitmargin", clear
ren pe pe_profitmargin
collapse pe_, by (pnr)
save "$project\manager\managerfe_profitmargin", replace

use "$project\manager\manager_fe_emp", clear
ren pe pe_emp
collapse pe_, by (pnr)
save "$project\manager\managerfe_emp", replace

use "$project\manager\manager_fe_jobcreation", clear
ren pe pe_jobcreation
collapse pe_, by (pnr)
save "$project\manager\managerfe_jobcreation", replace

use "$project\manager\manager_fe_quit", clear
ren pe pe_quit
collapse pe_, by (pnr)
save "$project\manager\managerfe_quit", replace

use "$project\manager\manager_fe_outflow", clear
ren pe pe_outflow
collapse pe_, by (pnr)
save "$project\manager\managerfe_outflow", replace

use "$project\manager\manager_fe_inflow", clear
ren pe pe_inflow
collapse pe_, by (pnr)
save "$project\manager\managerfe_inflow", replace


use "$project\managerfe_1step_over5", clear
ren me_bayes pe_wage
ren pnrm pnr

merge 1:1 pnr using "$project\manager\manager_fe_tfp", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_tfp2", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_vapp", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_leverage", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_input", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_logemp", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_hiring_rate", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_roa", keep(1 3) nogen
merge 1:1 pnr using "$project\manager\manager_fe_firing_rate", keep(1 3) nogen

foreach var in pe_wage  {
	sum `var',d
	replace `var'=r(p1) if `var'<r(p1)
	replace `var'=r(p99) if `var'>r(p99) & `var'!=.
}

reg pe_input pe_wage
keep if e(sample)==1
keep if pe_leverage!=.

gen temp=.
foreach var in pe_vapp pe_tfp pe_tfp2 pe_leverage pe_input pe_hiring_rate pe_firing_rate pe_logemp pe_roa pe_wage {
replace temp=`var'
drop `var'
egen `var'=std(temp)
}
drop temp

binscatter pe_vapp pe_wage , ytitle("Manager FE, value added per worker") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_vapp.png", as(png) name("Graph") replace

binscatter pe_tfp2 pe_wage , ytitle("Manager FE, TFP") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_tfp.png", as(png) name("Graph") replace

binscatter pe_leverage pe_wage , ytitle("Manager FE, leverage") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_leverage.png", as(png) name("Graph") replace

binscatter pe_input pe_wage , ytitle("Manager FE, input cost") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_input.png", as(png) name("Graph") replace

binscatter pe_logemp pe_wage , ytitle("Manager FE, employment") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_emp.png", as(png) name("Graph") replace

binscatter pe_roa pe_wage, ytitle("Manager FE, ROA") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_roa.png", as(png) name("Graph") replace

binscatter pe_hiring_rate pe_wage, ytitle("Manager FE, hiring rate") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_quit.png", as(png) name("Graph") replace

binscatter pe_firing_rate pe_wage, ytitle("Manager FE, firing rate") xtitle("Manager FE, wage") 
graph export "$project\corr_managerfe_inflow.png", as(png) name("Graph") replace


eststo clear

eststo: reg pe_vapp pe_wage, r
eststo: reg pe_tfp2 pe_wage, r
eststo: reg pe_leverage pe_wage, r
eststo: reg pe_input pe_wage, r
eststo: reg pe_logemp pe_wage, r
eststo: reg pe_roa pe_wage, r

estout using "$project\results\correlation_managerfe.xls", cells(b(fmt(4)) se(par fmt(4)))  legend stats(N, labels("No. of obs.")) varwidth(46) style(esttab) replace




